<style scoped>
</style>
<template>
  <HeaderSlot>
    <van-nav-bar :title="$t(this_action.label)" left-arrow @click-left="href_handle(-1)" />
  </HeaderSlot>
  <form_param :config="form_config" :submit="submit">
    <template #submit>
      <div style="padding: 0.5em 1em;">
        <van-button text="提交" type="primary" native-type="submit" round block />
      </div>
    </template>
  </form_param>

</template>

<script>
import form_param from "@/components/form_param.vue"
import router, {_get, href_handle} from "@/vue_plugin/router_auto.js";
import {ajax} from "@/js/api_tool.js";
import {use_config_map} from "@/store/config_map.js";
import HeaderSlot from "@/components/slot/HeaderSlot.vue";

export default {
  components: {HeaderSlot, form_param},
  props: {
    model: Object,
    this_action: Object,
  },
  data(){
    let refund_title_list = use_config_map().config.order?.refund_title_list || '无理由退款';
    let refund_title_map = refund_title_list.split("\n").map(v=>{
      return {content:v, value:v};
    })
    return {
      id: _get("id",0),
      form_config: [
        {name:"refund_apply[title]", label:"退款原因", type:"select_one", config:refund_title_map, value:"", tips:""},
        {name:"refund_apply[refund_money]", label:"退款金额", type:"text_one", config:'number', value:"", tips:""},
        {name:"", label:"换行", type:"br", value:"", tips:""},
        {name:"refund_apply[reason_user]", label:"补充描述", type:"text_more", value:"", tips:"", maxlength:120},
      ],
    }
  },
  methods:{
    href_handle,
    submit(form_data){
      let url = `/home/${this.model.name}/${this.this_action.action}?id=${this.id}`;
      ajax({url:url, data:form_data, method:'POST'}, (res)=>{
        setTimeout(()=>{ router.back(); }, 1000);
      })
    },
    init(){

    },
  },
  computed:{},
  mounted(){
    if (this.this_action.form_param_ids||1){
      let url = `/home/${this.model.name}/${this.this_action.action}?_is_init_=1&id=${this.id}`;
      ajax(url, (res)=>{
        this.form_config = Object.values(res.data).concat(this.form_config);
      })
    }
  }
}
</script>